package com.project.web.admin.interceptor;

import com.project.web.admin.utils.setting.SettingUtils;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.yun.common.utils.setting.Setting;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * setting拦截器
 */
public class SettingInterceptor extends HandlerInterceptorAdapter {

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        if (modelAndView != null && modelAndView.isReference()) {
            ModelMap modelMap = modelAndView.getModelMap();
            if (modelMap != null && !modelMap.containsAttribute("setting")) {
                Setting setting = SettingUtils.get();
                modelAndView.addObject("setting", setting);
            }
        }
    }
}
